<?php

namespace app\bbxw\command;


use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use think\admin\Command;
use think\console\Input;
use think\console\Output;
/**
 * 订单导入
 * Class SmsNum
 * @package app\common\command
 */
class UpdataCustomer extends Command
{
    /**
     * 配置指令
     */
    protected function configure()
    {
        $this->setName('xbbxw:updataCustomer');
        $this->setDescription('UpdataCustomer');
    }

    protected function execute(Input $input, Output $output)
    {
        $this->setQueueProgress("正在解析数据,请稍等...", 0);
        $use_amounts = $this->app->db->name("play_accompany")->field("sum(business_amount) as use_amount,uid")
            ->whereIn("payment_method","扣预存,扣专属预存")->group('uid')->select()->toArray();
        $prestore_amounts = $this->app->db->name("play_accompany")->field("sum(prepaid_amount) as prestore_amount,uid")
            ->group('uid')->select()->toArray();
        $total = count($use_amounts)+count($prestore_amounts);
        $count = 0;
        foreach ($use_amounts as $v){

            if($v['use_amount']){
                $this->app->db->name("customer")->where(['id'=>$v['uid']])->update(['use_amount'=>$v['use_amount']]);
            }
            $this->queue->message($total, ++$count, "正在更新消费金额...");
        }

        foreach ($prestore_amounts as $v){
            if($v['prestore_amount']){
                $this->app->db->name("customer")->where(['id'=>$v['uid']])->update(['prestore_amount'=>$v['prestore_amount']]);
            }
            $this->queue->message($total, ++$count, "正在更新预存金额...");
        }
        $this->setQueueSuccess("数据更新成功,请刷新页面");
    }
}